function message =metricMaketable(algs,dataName,dataResult,candiname)
message = [];
tex_header = '\begin{table*}';
tex_header = [tex_header, char(13),'\caption{','Clustering results measured by Accuracy/NMI/Purity of the compared methods','}'];
%tex_header = [tex_header, char(13),'\tiny \centering \label{table:res_aio}'];
tex_header = [tex_header, char(13),'\centering \label{table:res_aio} \setlength{\tabcolsep}{2.0pt}'];
tex_align = 'c';

tex_title = 'Data Sets';
tex_title = [tex_title,' & ', 'Metrics'];
tex_align = [tex_align,' c '];
for i1 = 1:length(algs)
    tex_title = [tex_title,' & ', algs{i1}];
    tex_align = [tex_align,' c '];
end
tex_title = [tex_title '\\ \hline'];
tex_header = [tex_header, char(13),'\begin{tabular}{', tex_align, '}'];
tex_header = [tex_header, char(13),'\toprule'];
accmeanval=zeros(length(dataName),length(candiname));
nmimeanval=zeros(length(dataName),length(candiname));
puritymeanval=zeros(length(dataName),length(candiname));
 for i2 = 1:length(dataName)
        acc = [];
        nmi=[];
        purity=[];
        for i3 = 1:length(candiname)
            candiname{i3}
            load(fullfile(pwd,'result', [dataResult{i2},'_',candiname{i3},'_multi_kernel']));
            a=eval(['res_',candiname{i3},'_aio'])
           acc = [acc;max(a(:,1))];
           nmi = [nmi;max(a(:,2))];
           purity = [purity;max(a(:,3))];
        end
        message = [message, char(13), mstex(acc,nmi, purity,dataName{i2})];
        accmeanval(i2,:)=acc';
        nmimeanval(i2,:)= nmi';
        puritymeanval(i2,:)=purity';
 end
message = [message, char(13), mstex(mean(accmeanval,1),mean(nmimeanval,1), mean(puritymeanval,1),'Average')];
message = [tex_title, char(13), message ];
tex_end = [];
tex_end = [tex_end, char(13), '\bottomrule' ];
tex_end = [tex_end, char(13), '\end{tabular}' ];
tex_end = [tex_end, char(13), '\end{table*}' ];
message = [tex_header, char(13), message, char(13), tex_end];
message = strrep(message, '_', '-');
fid=fopen(['Clustering results measured of the compared methods', '.tex'], 'w+');
fprintf(fid,'%s', message);
fclose(fid);
end


function t = mstex(acc, nmi, purity,prefix)
n = 10;
ismax=1;
n
t = prefix;
if strcmp(prefix,'Average')
    t=[t,'& \tabincell{c}{ mACC','\\', 'mNMI','\\','mPurity',' }'];
else    
t=[t,'& \tabincell{c}{ ACC','\\', 'NMI','\\','Purity','}'];
end
if ismax
    [~, idx] = max(acc);
else
    [~, idx] = min(acc);
end
for i1 = 1:n
    if i1 == idx
          t = [t, '& \tabincell{c}{ \textbf{', num2str(acc(i1), '%5.4f'),'}',  ' \\ \textbf{', num2str(nmi(i1), '%5.4f'),'}', ' \\ \textbf{', num2str(purity(i1), '%5.4f'),' }} '];
    else
          t = [t, '& \tabincell{c}{ ', num2str(acc(i1), '%5.4f'),  ' \\  ', num2str(nmi(i1), '%5.4f'), ' \\  ', num2str(purity(i1), '%5.4f'),' }'];
    end
end
t = [t, '\\ \hline'];    
end
